﻿using System.Net.Http.Formatting;

namespace CN2P.Web.App_Start
{
    using System.Web.Http;

    using CN2P.Web.Controllers.Api;
    using CN2P.Web.Controllers.Api.Proxy;
    using CN2P.Web.Routing;

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            var routes = config.Routes;

            routes.MapHttpRouteWithProxy<CartApiController, CartApiProxyController>("api.cart.get", "api/cart/{userId}", new { action = "Get" }, null, "GET");
            routes.MapHttpRouteWithProxy<CartApiController, CartApiProxyController>("api.cart.post", "api/cart/{userId}", new { action = "Post" }, null, "POST");
            routes.MapHttpRouteWithProxy<CartApiController, CartApiProxyController>("api.cart.delete", "api/cart/{userId}", new { action = "Delete" }, null, "DELETE");

            routes.MapHttpRouteWithProxy<CartApiController, CartApiProxyController>("api.cart.items.post", "api/cart/{userId}/items", new { action = "PostItem" }, null, "POST");
            routes.MapHttpRouteWithProxy<CartApiController, CartApiProxyController>("api.cart.items.put", "api/cart/{userId}/items/{prodId}", new { action = "PutItem" }, null, "PUT");
            routes.MapHttpRouteWithProxy<CartApiController, CartApiProxyController>("api.cart.items.delete", "api/cart/{userId}/items/{prodId}", new { action = "DeleteItem" }, null, "DELETE");
            routes.MapHttpRouteWithProxy<CartApiController, CartApiProxyController>("api.cart.checkout", "api/cart/{userId}/checkout", new { action = "Checkout" }, null, "POST");
            routes.MapHttpRouteWithProxy<CartApiController, CartApiProxyController>("api.cart.deleteAll", "api/cart/", new { action = "DeleteAll" }, null, "DELETE");

            routes.MapHttpRouteWithProxy<OrdersApiController, OrdersApiProxyController>("api.orders.list", "api/orders/{userId}/", new { action = "Get" }, null, "GET");
            routes.MapHttpRouteWithProxy<OrdersApiController, OrdersApiProxyController>("api.orders.item", "api/orders/{userId}/{orderId}", new { action = "GetOrder" }, null, "GET");
            routes.MapHttpRouteWithProxy<OrdersApiController, OrdersApiProxyController>("api.orders.deleteAll", "api/orders/", new { action = "DeleteAll" }, null, "DELETE");

            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.deleteAll", "api/product/", new { action = "DeleteAll" }, null, "DELETE");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.create", "api/product/", new { action = "Create" }, null, "POST");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.items.term", "api/product/search/name", new { action = "GetByTerm" }, null, "GET");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.tags", "api/product/tags", new { action = "GetTags" }, null, "GET");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.update", "api/product/{prodId}", new { action = "Update" }, null, "PUT");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.delete", "api/product/{prodId}", new { action = "Delete" }, null, "DELETE");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.item.get", "api/product/{prodId}", new { action = "Get" }, null, "GET");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.item.getDetails", "api/product/{prodId}/details", new { action = "GetDetails" }, null, "GET");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.items", "api/product/", new { action = "GetItems" }, null, "GET");
            routes.MapHttpRouteWithProxy<ProductsApiController, ProductsApiProxyController>("api.product.items.tags", "api/product/search/tag", new { action = "GetByTag" }, null, "GET");

            routes.MapHttpRouteWithProxy<ReviewsApiController, ReviewsApiProxyController>("api.product.reviews", "api/product/{prodId}/reviews/", new { action = "Get" }, null, "GET");
            routes.MapHttpRouteWithProxy<ReviewsApiController, ReviewsApiProxyController>("api.product.reviews.post", "api/product/{prodId}/reviews/", new { action = "Post" }, null, "POST");
            routes.MapHttpRouteWithProxy<ReviewsApiController, ReviewsApiProxyController>("api.product.reviews.get", "api/product/{prodId}/reviews/{reviewId}", new { action = "GetReview" }, null, "GET");
            routes.MapHttpRouteWithProxy<ReviewsApiController, ReviewsApiProxyController>("api.product.reviews.item.delete", "api/product/{prodId}/reviews/{reviewId}", new { action = "RemoveReview" }, null, "DELETE");
            routes.MapHttpRouteWithProxy<ReviewsApiController, ReviewsApiProxyController>("api.product.reviews.item.update", "api/product/{prodId}/reviews/{reviewId}", new { action = "UpdateReview" }, null, "PUT");

            routes.MapHttpRouteWithProxy<RecommendationsApiController, RecommendationsApiProxyController>("api.recommendation.get", "api/recommendation/", new { action = "Get" }, null, "GET");
            routes.MapHttpRouteWithProxy<RecommendationsApiController, RecommendationsApiProxyController>("api.recommendation.addTraversal", "api/recommendation/traversal", new { action = "AddTraversal" }, null, "POST");
            routes.MapHttpRouteWithProxy<RecommendationsApiController, RecommendationsApiProxyController>("api.recommendation.deleteAll", "api/recommendation/", new { action = "DeleteAll" }, null, "DELETE");

            routes.MapHttpRouteWithProxy<SessionApiController, SessionApiProxyController>("api.session.items.getByUser", "api/vieweditems/{userId}", new { action = "Get" }, null, "GET");
            routes.MapHttpRouteWithProxy<SessionApiController, SessionApiProxyController>("api.session.items.post", "api/vieweditems/", new { action = "Post" }, null, "POST");
        }
    }
}
